package com.lris.rest;

import com.alibaba.fastjson2.JSON;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result<T> {

    private String name;

    private LocalDateTime time;

    private T message;

    public Result(T message) {

    }

    public static TextWebSocketFrame fail (String message ){
        return  new TextWebSocketFrame(JSON.toJSONString(new Result("系统消息",LocalDateTime.now(),message)));
    }

    public static TextWebSocketFrame success (String message ){
        return  new TextWebSocketFrame(JSON.toJSONString(new Result("系统消息",LocalDateTime.now(),message)));
    }

    public static TextWebSocketFrame success (String user,String message ){
        return  new TextWebSocketFrame(JSON.toJSONString(new Result(user,LocalDateTime.now(),message)));
    }
    public static <T>TextWebSocketFrame success (T message ){
        return  new TextWebSocketFrame(JSON.toJSONString(message));
    }
}
